package com.ssl.basics.list;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

/**
 * 描述：
 *
 * @author shi_senlin
 * @create 2021/07/10 9:30
 */
public class MapSafe {
    // static Map<Integer, Integer> map = new ConcurrentHashMap<>();
    static Map<Integer, Integer> map = Collections.synchronizedMap(new HashMap<>());

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 100; j++) {
                    map.put(j, j);
                }
                latch.countDown();
            }, "AA").start();
        }
        latch.await();
        System.out.println(map);
        System.out.println(map.size());
    }
}
